<?php
/*
 * 网站的权限判定, 使用传入的页面和当前的管理员组进行权限的判定.
 * @author  Mark
 * @package ixdcw
 * @file    Auth.class.php
 * @time    13-3-26 上午11:08
 */
class Auth {

	const AUTH_GROUP_INDEX   = 'index';
	const AUTH_GROUP_LIST    = 'list';
	const AUTH_GROUP_SHOW    = 'show';
	const AUTH_GROUP_SEARCH  = 'search';
	const AUTH_GROUP_COMPARE = 'compare';
	const AUTH_GROUP_REFRESH = 'refresh';
	const AUTH_GROUP_COLOR   = 'color';
	const AUTH_GROUP_CONTACT = 'contact';

	public static function genSwfUpload($userid, $username, $groupid) {
		global $DT_IP;
		return md5($userid . $username . $groupid . DT_KEY . $DT_IP);
	}

	public static function checkSwfUpload($uUid, $uUname, $uGroupid, $uAuth) {
		global $DT_IP;
		return md5($uUid . $uUname . $uGroupid . DT_KEY . $DT_IP) === $uAuth;
	}

	/**
	 *
	 */
	public static function check($authType) {
		$modTypes = self::getGroupAuth($authType);
		$groupid  = $GLOBALS['_groupid'];
		if (empty($modTypes)) {
			return true;
		} else {
			return in_array($groupid, $modTypes);
		}
	}

	private static function getGroupAuth($authType) {
		$modType = $GLOBALS['MOD']['group_' . $authType];
		if (!isset($modType) || empty($modType)) {
			return array();
		} else {
			return explode(',', $modType);
		}
	}
}